package cn.edu.ctbu.jpatest.dao;

import cn.edu.ctbu.jpatest.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author xiaopeng
 * @version 1.0
 */
public interface StudentRepository extends JpaRepository<Student,Integer> {
    /**
     * 根据姓名模糊查询 (like)
     * @param name
     * @return
     */
    List<Student> findByNameLike(String name);

    @Modifying
    @Query("DELETE FROM tb_student s WHERE s.id IN :ids")
    void deleteByIds(List<Integer> ids);

    /**
     * 根据姓名模糊查询 (startingWith)
     * @param name
     * @return
     */
    List<Student> findByNameStartingWith(String name);

    /**
     * 根据姓名和密码查询
     * @param name
     * @param password
     * @return
     */
    List<Student> findByNameAndPassword(String name,String password);

    /**
     * 根据学号查询
     * @param sno
     * @return
     */
    Student findBySno(String sno);


}
